//
//  CZEmoticonKeyboardView.swift
//  CZVVeiBo
//
//  Created by smile on 2017/8/6.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

class CZEmoticonKeyboardView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = UIColor(patternImage: UIImage(named:"emoticon_keyboard_background")!)
        // 大小
        frame.size = CGSize(width: CZSCREENW, height: 216)
        
        addSubview(bottomView)
        addSubview(pageView)
        
        bottomView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(35)
        }
        
        pageView.snp.makeConstraints { (make) in
            make.left.right.top.equalTo(self)
            make.bottom.equalTo(bottomView.snp.top)
        }
        
        // 监听按钮点击
        bottomView.closure = {(type)->() in
            
            switch type {
            case .normal:
                print("默认")
            case .emoji:
                print("emoji")
            case .lxh:
                print("lxh")

            }
            let indexPath = IndexPath(item: 0, section: type.rawValue - 2001)
            // 滚动到指定的组
            self.pageView.scrollToItem(at: indexPath, at: UICollectionViewScrollPosition.left, animated: false)
        }
    }

    // MARK: - 懒加载控件
    private lazy var bottomView: CZEmoticonBottomView = CZEmoticonBottomView()
    // 
    private lazy var pageView: CZEmoticonPageView = {
        let view = CZEmoticonPageView()
        // 取消弹簧效果
        view.bounces = false
        // 分页
        view.isPagingEnabled = true
        // 隐藏垂直和水平滚动条
        view.showsVerticalScrollIndicator = false
        view.showsHorizontalScrollIndicator = false
        return view
    }()
}
